# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=hfsprogs
_pkgname=diskdev_cmds
pkgver=540.1_p3
_pkgver=${pkgver/_p/.linux}
pkgrel=4
pkgdesc="Tools to create/check Apple HFS+ filesystems"
# We use modified version provided by Fedora's dev, not directly from Apple.
url="https://src.fedoraproject.org/rpms/hfsplus-tools"
arch="all !mips !mips64" # broken on soft-float
license="APSL-2.0"
makedepends="clang libbsd-dev openssl-dev linux-headers util-linux-dev"
provides="$_pkgname=$pkgver-r$pkgrel"
subpackages="$pkgname-doc"
# Tarball made by Matthew Garrett (mjg59).
# https://src.fedoraproject.org/rpms/hfsplus-tools/blob/f27/f/hfsplus-tools.spec
source="http://cavan.codon.org.uk/~mjg59/$_pkgname/$_pkgname-$_pkgver.tar.gz
	APSL-2.0.txt
	fix-stdarg.patch
	musl-compat.patch"
builddir="$srcdir/$_pkgname-$_pkgver"

prepare() {
	default_prepare
	cd "$builddir"

	sed -i 's/[F|f]sck_hfs/fsck.hfsplus/g' fsck_hfs.tproj/fsck_hfs.8
	sed -i 's/[N|n]ewfs_hfs/mkfs.hfsplus/g' newfs_hfs.tproj/newfs_hfs.8

	# Remove errant execute bits.
	find . -type f -name '*.[ch]' -exec chmod -c -x {} +
}

build() {
	cd "$builddir"

	make
}

check() {
	cd "$builddir"

	./fsck_hfs.tproj/fsck_hfs 2>&1 | grep 'usage: fsck_hfs'
	./newfs_hfs.tproj/newfs_hfs 2>&1 | grep 'usage: newfs_hfs'
}

package() {
	cd "$builddir"

	install -D -m 755 fsck_hfs.tproj/fsck_hfs "$pkgdir"/usr/sbin/fsck.hfs
	install -D -m 755 newfs_hfs.tproj/newfs_hfs "$pkgdir"/usr/sbin/mkfs.hfsplus
	ln -s fsck.hfs "$pkgdir"/usr/sbin/fsck.hfsplus

	install -D -m 644 fsck_hfs.tproj/fsck_hfs.8 \
		"$pkgdir"/usr/share/man/man8/fsck.hfsplus.8
	install -D -m 644 newfs_hfs.tproj/newfs_hfs.8 \
		"$pkgdir"/usr/share/man/man8/mkfs.hfsplus.8
	ln -s fsck.hfs.8 "$pkgdir"/usr/share/man/man8/fsck.hfs.8

	install -D -m 644 "$srcdir"/APSL-2.0.txt \
		"$pkgdir"/usr/share/licenses/$pkgname/APSL-2.0.txt
}

sha512sums="3d88fcdec4bfd32a75b6dc75899748d8585371b641be86cfdfe54ade738a0612662dd008c1506c7e216325303217d0b5f188a9c4fdccfb48b2ce50333f212d9e  diskdev_cmds-540.1.linux3.tar.gz
76a53cc22e92e12d6255fc6ee0b9b65e03ef0d590e8bdbf06e9861a5f024f25c5344ce8426ca8f81d8544d86004be02f806ad60517165a9f6d9dfd6f31790c21  APSL-2.0.txt
cff25de690f5ecc418380e5cbda3615d38ef9583ace60be9b7696c50e46bc35a29855b216ddb4daae79ff5b40f66ffbc03f613ab0ae1935ee9df6e69caed2e0b  fix-stdarg.patch
34c73b0b57c8e8fa64abf34a9396b6dc218b1a1f06fec98fd52e77c81421cff249f4a65d5f26e692b1cb5e2424a871ecbf5b35eab5d3509506f6710406ff7577  musl-compat.patch"
